package com.example.bilibili.func;

import com.example.bilibili.entity.Bvideo;
import lombok.Data;

import java.text.SimpleDateFormat;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.Date;
import java.util.List;

@Data
public class VResult {
    private BVObj data;
    public static final SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
    public static final DateTimeFormatter dtf = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");

    public static Bvideo trans(BVideo w, String type) {
        Bvideo bvideo = new Bvideo();
        bvideo.setId(w.getAid())
                .setBid(w.getBvid())
                .setUid(w.getOwner().getMid())
                .setTitle(w.getTitle())
                .setDuration(w.getDuration())
                .setPic(w.getPic())
                .setDescription(w.getDesc())
                .setPublocation(w.getPub_location())
                .setWidth(w.getDimension().getWidth())
                .setHeight(w.getDimension().getHeight())
                .setView(w.getStat().getView())
                .setDanmu(w.getStat().getDanmaku())
                .setReply(w.getStat().getReply())
                .setFavorite(w.getStat().getFavorite())
                .setCoin(w.getStat().getCoin())
                .setShare(w.getStat().getShare())
                .setLike(w.getStat().getLike())
                .setType(type)
                .setGtime(LocalDateTime.now().format(dtf))
                .setPubdate(sdf.format(new Date(w.getPubdate() * 1000L)));
        return bvideo;
    }
}

@Data
class BVObj {
    private List<BVideo> list;
}

@Data
class BVideo {
    private String aid;
    private String bvid;
    private Owner owner;
    private String title;
    private int duration;
    private String pic;
    private int pubdate;
    private String desc;
    private Stat stat;
    private Dimension dimension;
    private String pub_location;
}

@Data
class Owner {
    private String mid;
}

@Data
class Stat {
    private int view;
    private int danmaku;
    private int reply;
    private int favorite;
    private int coin;
    private int share;
    private int like;
}

@Data
class Dimension {
    private int width;
    private int height;
}